package org.example.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Copyright: Copyright (c) 2022 Asiainfo
 *
 * @ClassName: org.example.config.CorsConfig
 * @Description: 配置springsecurity的跨域配置
 * @version: v1.0.0
 * @author: 炫沙糖桔的鹏仔
 * @date: 2022/8/9 16:07
 * <p>
 * Modification History:
 * Date         Author          Version            Description
 * ------------------------------------------------------------
 * 2022/8/9      炫沙糖桔的鹏仔          v1.0.0               修改原因
 */

@Configuration
public class CorsConfig implements WebMvcConfigurer {
    /**
     * @param registry
     */
    @Override
    public void addCorsMappings(CorsRegistry registry) {
//        配置允许跨域的路径
        registry.addMapping("/**")
//                配置允许跨域请求的域名
                .allowedOriginPatterns("*")
                .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
                .allowedHeaders("*")
//                配置是否运行cookie
                .allowCredentials(true)
                .maxAge(3600);
    }
}
